import 'package:boss/ui/page/commodity/material/page/materialDetail/provider/material_detail_provider.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class MaterialDetailForm extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: SingleChildScrollView(
        padding: EdgeInsets.symmetric(
          horizontal: 30.w,
        ),
        child: Column(
          children: <Widget>[
            Consumer<MaterialDetailProvider>(
              builder: (context, materialDetailProvider, child) {
                return BaseTextFormField(
                  prefixText: '加料/配菜名称',
                  hintText: '例如：香菜',
                  initialValue: materialDetailProvider.data.meterialName,
                  onChanged: (value) {
                    materialDetailProvider.data.meterialName = value;
                  },
                );
              },
            ),
            Consumer<MaterialDetailProvider>(
              builder: (context, materialDetailProvider, child) {
                return BaseTextFormField(
                  prefixText: '价格',
                  hintText: '请输入',
                  suffixText: '元',
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                  inputFormatters: [
                    FilteringTextInputFormatter.allow(RegUtil.numberReg),
                  ],
                  initialValue: materialDetailProvider.data.meterialPrice == 0 ? '' : AmountUtil.price2String(materialDetailProvider.data.meterialPrice),
                  onChanged: (value) {
                    try {
                      materialDetailProvider.data.meterialPrice = AmountUtil.string2Price(value);
                    } catch (e) {
                      materialDetailProvider.data.meterialPrice = -1;
                    }
                  },
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
